#include "spl.includes.h"
#include "splib.h"

using namespace SPLib;
using namespace SPLib::Windows;

ULONG FrameWnd::DropSource::AddRef()
{
  return InterlockedIncrement(&m_lRefCount);
}

ULONG FrameWnd::DropSource::Release()
{
  LONG count = InterlockedDecrement(&m_lRefCount);

  if (count)
    return count;

  delete this;
  return 0;
}

HRESULT FrameWnd::DropSource::QueryInterface(REFIID iid, void **ppvObjectOut)
{
  if (iid == IID_IDropSource || iid == IID_IUnknown)
  {
    AddRef();
    *ppvObjectOut = this;
    return S_OK;
  }
  else
  {
    *ppvObjectOut = 0;
    return E_NOINTERFACE;
  }
}

HRESULT FrameWnd::DropSource::QueryContinueDrag(BOOL fEscapePressed,
  DWORD grfKeyState)
{
  Event::QueryContinueDragEvent wEvent(fEscapePressed, grfKeyState);

  return wnd->onQueryContinueDrag(wEvent);
}

HRESULT FrameWnd::DropSource::GiveFeedback(DWORD dwEffect)
{
  Event::DragFeedbackEvent wEvent(dwEffect);

  return wnd->onGiveFeedback(wEvent);
}

FrameWnd::DropSource::DropSource(FrameWnd *wnd) : m_lRefCount(1)
{
  this->wnd = wnd;
}